﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.SessionState;

namespace uploadify_Test.uploadify
{
    /// <summary>
    /// uploadifyHandler 的摘要说明
    /// </summary>
    public class uploadifyHandler : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            HttpPostedFile file = context.Request.Files["Filedata"];
            string uploadPath = HttpContext.Current.Server.MapPath("\\uploadfiles\\");
            //string jingqu = HttpContext.Current.Server.MapPath("\\uploadfiles\\news\\");
            //string jieshao = HttpContext.Current.Server.MapPath("\\uploadfiles\\jieshao\\");
            //后台管理员的userid
            //int id = 0;
            //if (context.Request.QueryString["op"] != null && context.Request.QueryString["op"].Equals("putong"))
            //{
            //    id = Convert.ToInt32(context.Session["userid"]);
            //}
            //else
            //{
            //    id = Convert.ToInt32(context.Session["useradmin"]);
            //}
            if (file != null)
            {
              if (!System.IO.Directory.Exists(uploadPath))
                {
                  System.IO.Directory.CreateDirectory(uploadPath);
                }
                //重命名图片名称id +
                string filename =  DateTime.Now.ToString("yyyymmddhhmmss_ffff") + Path.GetExtension(file.FileName);
                file.SaveAs(uploadPath + filename);
                //file.SaveAs(jingqu + filename);
                //file.SaveAs(jieshao + filename);
                context.Response.Write("1," + filename);

                //存入session
              
            }
            else
            {
                context.Response.Write("0");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}